﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class FacilitiesBussiness : IDbServices<bool, int, TblFacility>
    {
        private BookingDBForWinFormEntities1 db = new BookingDBForWinFormEntities1();


        public bool AddData(TblFacility e)
        {
            try
            {

                db.TblFacilities.Add(e);
                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return false;
            }
        }

        public bool UpdateData(TblFacility e)
        {
            try
            {

                db.Entry(e).State = EntityState.Modified;
                db.SaveChanges();
                return true;
            }
            catch (ValidationException ex)
            {

                return false;
            }
        }

        public bool DeleteData(int k)
        {
            TblFacility objFacility = new TblFacility();
            objFacility = db.TblFacilities.Find(k);
            try
            {
                db.TblFacilities.Remove(objFacility);
                db.SaveChanges();
                return true;

            }
            catch (DbUpdateConcurrencyException)
            {

                return false;
            }
        }

        public TblFacility GetDataByKey(int k)
        {
            try
            {
                return db.TblFacilities.Find(k);
            }
            catch (Exception)
            {

                return null;
            }
        }

        public List<TblFacility> GetAll()
        {
            try
            {
                return db.TblFacilities.ToList<TblFacility>();
            }
            catch (Exception)
            {

                return null;
            }
        }
    }
}
